<?php
function login_verify(string $user,string $passwd):string
{
    global $db;
    require_once "../tool/sql.php";
	$verify = 1;
	if($db->connected()) {
		$res = $db->selectById("userinfo","passwd","name",$user);
        if($res != null) {
            foreach ($res as $real_wd) {
                if($real_wd['passwd'] == ($passwd))
                    $verify = 0;
            }
        }

	}else{
		$verify = $db->getConnectError();
	}
	$db->close();
	unset($db);
	return $verify;
}
if (isset($_POST["user"])){
	if(($v=login_verify($_POST["user"],$_POST["passwd"])) == "0") {
		session_start();
		$_SESSION['user'] = $_POST["user"];
        $t = time() + 3600*24*3;
		$_SESSION['login_timeout'] = $t;
        setcookie(session_name(), session_id(), $t, "/");
	}
	echo $v;
}

